package org.ricks.common.conf;

import org.ricks.utils.PackageUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2020/8/717:05
 */
public class ClassHandler {

    private Set<Class<?>> classSet;
    private Map<Class<?>, LoadFileName> fixedClassMap = new HashMap<>();

    private static ClassHandler classHandler;

    private ClassHandler() {
    }

    public static ClassHandler getClassHandler() {
        // singleton
        if (Objects.isNull(classHandler)) {
            synchronized (ClassHandler.class) {
                if (Objects.isNull(classHandler)) {
                    classHandler = new ClassHandler();//初始化对象
                    classHandler.classSet = PackageUtils.getClasses(ConfStarter.class.getPackageName());//扫描包所有的类
                }
            }
        }
        return classHandler;
    }

    public Set<Class<?>> getClassSet() {
        return classSet;
    }

    public Set<Class<?>> addClassSet(Set<Class<?>> classes) {
        classSet.addAll(classes);
        return classSet;
    }

    public Map<Class<?>, LoadFileName> getFixedClassMap() {
        return fixedClassMap;
    }
}

